package com.yunshipei.model;

import android.text.TextUtils;
import android.util.Log;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by cike on 15-11-19.
 */
public class DateTime implements Serializable {
    private String date = "";        //语音识别出的日期时间
    private String dateOrig = "";    //日期时间的描述
    private String time = "";        //语音识别出的的时间
    private String timeOrig = "";    //时间的描述
    private DecimalFormat decimalFormat = null;

    public DateTime() {
        decimalFormat = new DecimalFormat("00");
        Calendar calendar = Calendar.getInstance();
        this.date = calendar.get(Calendar.YEAR) + "-" + decimalFormat.format(calendar.get(Calendar.MONTH) + 1) + "-" + decimalFormat.format(calendar.get(Calendar.DATE));
        this.time = calendar.getTime().getHours()+ ":" + decimalFormat.format(calendar.getTime().getMinutes()) + ":" + decimalFormat.format(calendar.getTime().getSeconds());
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getDateOrig() {
        return dateOrig;
    }

    public void setDateOrig(String dateOrig) {
        this.dateOrig = dateOrig;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getTimeOrig() {
        return timeOrig;
    }

    public void setTimeOrig(String timeOrig) {
        this.timeOrig = timeOrig;
    }

    public long getFormatDate() {
        String recognitionTime;
        Date date = null;
        try {
            if (!TextUtils.isEmpty(getDate()) || !TextUtils.isEmpty(getTime())) {
                recognitionTime = getDateString();
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                date = df.parse(recognitionTime);
                return date.getTime();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public Date getInfactDate() {
        String recognitionTime;
        Date date = new Date();
        if (!TextUtils.isEmpty(getDate()) || !TextUtils.isEmpty(getTime())) {
            recognitionTime = getDateString();
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                date = df.parse(recognitionTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return date;
    }

    public String getDateString() {
        return getDate() + " " + getTime();
    }
}